import React, { useEffect, useState } from "react";
import watcher from "@/utils/watcher";
export default function Listener() {
  const [names, setNames] = useState<string[]>([]);
  useEffect(() => {
    return watcher.addListener((name) => {
      setNames((pre) => [...pre, name]);
    });
  }, []);
  return (
    <>
      <div>收到names:</div>
      {names.map((nm, i) => (
        <div key={i}>{nm}</div>
      ))}
    </>
  );
}
